package com.waigoulin.infrastructure.adapter.port;

import com.waigoulin.domain.order.adapter.port.IProductPort;
import com.waigoulin.domain.order.model.entity.ProductEntity;
import com.waigoulin.infrastructure.gateway.ProductRPC;
import com.waigoulin.infrastructure.gateway.dto.rpc.ProductDTO;
import org.springframework.stereotype.Service;

/**
 * @FileName ProductPort
 * @Description 商品查询基础设施层接口实现类
 * @Author waigoulin
 * @date 2025-07-31
 **/
@Service
public class ProductPort implements IProductPort {

    private final ProductRPC productRPC;

    // 通过构造器注入
    public ProductPort(ProductRPC productRPC) {
        this.productRPC = productRPC;
    }

    @Override
    public ProductEntity queryProductsByProductId(String productId) {
        ProductDTO productDTO = productRPC.queryProductsByProductId(productId);
        return ProductEntity.builder()
                .productId(productDTO.getProductId())
                .productName(productDTO.getProductName())
                .productDesc(productDTO.getProductDesc())
                .price(productDTO.getPrice())
                .build();
    }
}


